<?php

$traduccion = new Zend_Translate('array', APPLICATION_PATH . '/idiomas/es.php', 'es');  
Zend_Form::setDefaultTranslator($traduccion); 

class Application_Form_Material extends Zend_Form
{

    protected function generaDecorador($id) {
         return array(
                    'Errors',
                    'ViewHelper',
                    'Description',
                    array('Label',array('class' => 'imitar_h2')),
                    array('HtmlTag', array('tag' => 'Fieldset', 'id' => $id, 'class' => 'elemento' ))
                ); 
    }
    
    public function init()
    {
        
        $upload = Zend_Registry::get('upload_paths');
        //para sabr que decoradores declarar mire el
        //archivo Zend/Form/Element/File.php línea 77
        $file = new Zend_Form_Element_File('material');
        $file->setLabel('Cargar un Material:')
            ->setDestination($upload->paths->upload->files->materiales)
            ->setRequired(true)
            ->setDecorators(array(
                    'File',
                    'Errors',
                    'Description',
                    array('Label',array('class' => 'imitar_h2')),
                    array('HtmlTag', array('tag' => 'Fieldset', 'id' => 'fieldset_material', 'class' => 'elemento' ))
                ))
            ->setDescription('Las extensiones permitidas son: .pdf .zip .rar .tar .tar.gz');
        $file->addValidator('Count', false, 1);                // ensure only 1 file
        $file->addValidator('Extension', false, 'pdf,txt,zip,rar,tar,tar.gz');

        $this->addElement($file);
        
        /* Form Elements & Other Definitions Here ... */
        $this->addElement(
            'textarea', 'descripcion', array(
                    'decorators' => $this->generaDecorador("fieldset_descripcion"),
                    'label' => 'Descripción:',
                    'required' => true,
                    array('alpha')
                )
        );
        
        $this->addElement(
            'text', 'clave', array(
                    'decorators' => $this->generaDecorador("fieldset_clave"),
                    'label' => 'Clave:',
                    array('alpha')
                )
        );
        
        $this->addElement(
            'submit', 'Cargar', array('class' => 'btn btn-large btn-warning')
        );
        
        $this->setAction('/materiales/cargar');
        $this->setMethod('post');
                
    }

}
